package dict.agency;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import utils.MailUtil;

public class HrtDict {

	public static Map<String, String> STATE = new HashMap<String, String>();
	public static Map<String, String> RISK = new HashMap<String, String>();
	public static Map<String, Long> ALERT = new HashMap<String, Long>();
	public static Map<String, Long> HIDE = new HashMap<String, Long>();

	static {

		STATE.put("00", "Congratulations ,transaction successful");// 成功
		STATE.put("01", "Check issuer");// 查發卡行
		STATE.put("02", "Check issuer");// 查發卡行
		STATE.put("03", "Invalid merchant");// 無效商戶
		STATE.put("04", "Confiscate the card");// 沒收卡
		STATE.put("05", "Do not honor");// 联系不到发卡行 本次交易失败
		STATE.put("06", "Do not honor");// 联系不到发卡行 本次交易失败
		STATE.put("07", "Confiscate the card under special conditions");// 特殊條件下沒收卡
		STATE.put("12", "Invalid transaction");// 無效交易
		STATE.put("13", "Invalid amount");// 無效金額
		STATE.put("14", "Invalid card number");// 無效卡號
		STATE.put("15", "Invalid card issuers");// 本次交易没有查询得到发卡行
		STATE.put("19", "Re-enter the transaction");// 重新輸入交易
		STATE.put("30", "format error");// 格式錯誤
		STATE.put("33", "Expired card");// 過期的卡
		STATE.put("34", "Cheating suspected");// 有作弊嫌疑
		STATE.put("35", "Merchants need to contact closed security line");// 商戶需與收單行保安部門聯系
		STATE.put("36", "Restricted card");// 交易信用卡受到发卡行限制，不允许做交易
		STATE.put("37", "Merchants call to receive special security services");// 商戶呼收單行保安部門
		STATE.put("38", "Excess Inkyo specific PIN attempts import");// 超過允許的PIN試輸入
		STATE.put("39", "Without the credit card account");// 無此信用卡賬戶
		STATE.put("41", "Reported for loss card");// 信用卡已被挂失
		STATE.put("43", "Stolen card");// 被盗窃的信用卡
		STATE.put("51", "Without enough deposit");// 無足够的存款
		STATE.put("54", "Expired card");// 過期的卡
		STATE.put("55", "Excess Inkyo specific PIN attempts import");// 不正確的PIN
		STATE.put("57", "Do not allow cardholders to deal");// 发卡行不允许持卡人进行交易
		STATE.put("58", "Do not allow the terminal for trading");// 不允許終端進行的交易
		STATE.put("59", "Cheating suspected");// 有作弊嫌疑
		STATE.put("60", "Merchants to contact security");// 商戶與保安部聯系
		STATE.put("61", "Beyond the amount limit");// 超出取款金額限制
		STATE.put("62", "Restricted card");// 信用卡受到发卡行限制不允许本次交易
		STATE.put("63", "Violation safety hermetically provisions");// 違反安全保密規定
		STATE.put("65", "Card issuers bank refuse");// 違反安全保密規定
		STATE.put("66", "Merchants call to receive the security line");// 商戶呼收單行保安部
		STATE.put("69", "Trancation Failed");// 商戶呼收單行保安部
		STATE.put("70", "Undefine Error,Please contact the issuing bank");// 商戶呼收單行保安部
		STATE.put("75", "Mascotas para introducir el número PIN invadido");// 允許的輸入PIN次數超限
		STATE.put("76", "Please contact the issuing bank");// 請聯絡發卡銀行
		STATE.put("77", "Amount of money mistake");// 金額錯誤
		STATE.put("89", "Terminal code wrong");// 終端機代號錯
		STATE.put("91", "Issuer or switching center can not operate");// 發卡行或交換中心不能操作
		STATE.put("92", "Financial institution or intermediary network facilities can not be found or could not be reached");// 金融機構或中間網絡設施找不到或
		STATE.put("93", "Trading is illegal, you can't accomplish");// 交易違法，不能完成
		STATE.put("94", "Repeat trade");// 重覆交易
		STATE.put("95", "Regulation refrain system complex");// 調節控制錯
		STATE.put("96", "System failure");// 系統失效
		STATE.put("98", "Exchange centre not get card issuers response");// 交換中心收不到發卡行應答
		STATE.put("XX", "Can not support transaction");// 发卡行不支持本次交易
		STATE.put("YX", "Card Bin not allow DCC transaction");// 卡本不允许DCC事务
		STATE.put("YY", "Card Bin allow DCC transaction");// 卡本允许DCC事务
		STATE.put("YZ", "YZ dual-currency card to refusal of payment");// YZ
		STATE.put("N7", "CVV verify error,the transaction failed");// CVV输入不正确，本次交易失败
		STATE.put("H4", "Hrt Time Out");// CVV输入不正确，本次交易失败
		STATE.put("H5", "Bank System Failure");// CVV输入不正确，本次交易失败
		STATE.put("KO", "Site Forbidden");// CVV输入不正确，本次交易失败
		STATE.put("E3", "Pending");// CVV输入不正确，本次交易失败
		STATE.put("TM", "Unknown");// CVV输入不正确，本次交易失败
		STATE.put("100", "Time Out");// CVV输入不正确，本次交易失败
		STATE.put("101", "High Risk");// CVV输入不正确，本次交易失败
		STATE.put("103", "Repeated");// CVV输入不正确，本次交易失败
		STATE.put("104", "Format Error");// CVV输入不正确，本次交易失败
		STATE.put("105", "Off Limit");// CVV输入不正确，本次交易失败
		STATE.put("106", "Version Error");// CVV输入不正确，本次交易失败
		STATE.put("107", "Forbidden Country");// CVV输入不正确，本次交易失败

		RISK.put("41", "41");
		RISK.put("43", "43");
		RISK.put("04", "04");
		RISK.put("39", "39");
		RISK.put("41", "41");
		RISK.put("43", "43");
		RISK.put("54", "54");
		RISK.put("07", "07");
		RISK.put("58", "58");
		RISK.put("59", "59");
		RISK.put("60", "60");
		RISK.put("62", "62");

		ALERT.put("555", 0L);
		ALERT.put("01", 0L);
		ALERT.put("KO", 0L);

		// HIDE.put("9905", 0);
	}

	public static synchronized String message(String code) {
		if (STATE.containsKey(code)) {
			return STATE.get(code).toString();
		}
		return "unknown exception";
	}

	public static synchronized void warning(String code, int limit) {
		String name = "HRT";
		String time = new SimpleDateFormat("HH:mm:ss").format(new Date());
		if (ALERT.containsKey(code)) {
			ALERT.put(code, ALERT.get(code) + 1);
			if (new Integer(ALERT.get(code).toString()) > limit) {
				ALERT.put(code, 0L);
				MailUtil.sendEmail(MailUtil.tos, "警告", "[" + time + "]" + name + "返回码[" + code + "]超过[" + limit + "]次");
			}
		}
	}

}
